package com.lemon.utils.wx;

import java.util.HashMap;

import com.alibaba.fastjson.JSON;

public class TemplateData {

    private String touser;
    private String template_id;
    private String page;
    private String form_id;
    private String color;
    private TemplateItem data;
    private Miniprogram miniprogram;

    public static TemplateData newInstance() {
        return new TemplateData();
    }

    private TemplateData() {
        this.data = new TemplateItem();
        this.miniprogram = new Miniprogram();
    }

    public String getTouser() {
        return touser;
    }

    public TemplateData setTouser(String touser) {
        this.touser = touser;
        return this;
    }

    public String getTemplate_id() {
        return template_id;
    }

    public TemplateData setTemplate_id(String template_id) {
        this.template_id = template_id;
        return this;
    }

    
    public TemplateItem getData() {
        return data;
    }
 
    public String getPage() {
		return page;
	}

	public TemplateData setPage(String page) {
		this.page = page;
		 return this;
	}

	public String getForm_id() {
		return form_id;
	}

	public TemplateData setForm_id(String form_id) {
		this.form_id = form_id;
		 return this;
	}

	public String getColor() {
		return color;
	}

	public TemplateData setColor(String color) {
		this.color = color;
		 return this;
	}
	public TemplateData setMiniprogramAppid(String appid) {
		this.miniprogram.put("appid", appid);
		return this;
	}
	public TemplateData setMiniprogramPagepath(String pagepath) {
		this.miniprogram.put("pagepath", pagepath);
		 return this;
	}

    public TemplateData add(String key, String value){
        data.put(key, new Item(value, ""));
        return this;
    }

    public TemplateData add(String key, String value, String color){
        data.put(key, new Item(value, color));
        return this;
    }

    /**
     * 直接转化成jsonString
     * @return {String}
     */
    public String build() {
        return JSON.toJSONString(this);
    }

    public Miniprogram getMiniprogram() {
		return miniprogram;
	}

	private class TemplateItem extends HashMap<String, Item> {

        private static final long serialVersionUID = -3728490424738325020L;

        public TemplateItem() {}

    }
    private class Miniprogram extends HashMap<String, String> {

        private static final long serialVersionUID = -3728490424738325021L;

        public Miniprogram() {}

    }
    
    private class Item {
        private Object value;
        private String color;

        public Object getValue() {
            return value;
        }
        public void setValue(Object value) {
            this.value = value;
        }
        public String getColor() {
            return color;
        }
        public void setColor(String color) {
            this.color = color;
        }

        public Item(Object value, String color) {
            this.value = value;
            this.color = color;
        }
    }
}

